//
//  SearchTitleSectionView.m
//  GC_OC
//
//  Created by Macbook Pro on 2023/4/24.
//

#import "SearchTitleSectionView.h"
#import "SearchTitleModel.h"

@interface SearchTitleSectionView ()

@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UILabel *tagLabel;

@end

@implementation SearchTitleSectionView

- (void)setupSubviews
{
    [super setupSubviews];
    
    UIView *bgView = [[UIView alloc] init];
    [self.contentView addSubview:bgView];
//    bgView.backgroundColor = [UIColor fk_colorWithHex:0xf5f5f5];
    bgView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    UILabel *titleLabel = [UILabel fk_labelWithFont:fk_adjustFont(14) textColor:fkColor999999];
    [bgView addSubview:titleLabel];
    self.titleLabel = titleLabel;
    
    UILabel *tagLabel = [UILabel fk_labelWithFont:fk_adjustFont(11) textColor:fkColor333333 textAlignment:NSTextAlignmentCenter];
    [bgView addSubview:tagLabel];
    self.tagLabel = tagLabel;
    tagLabel.backgroundColor = [UIColor fk_colorWithHex:0xff9c9c];
    [tagLabel fk_viewCornerRadius:fk_adjustW(9) borderWidth:0 borderColor:nil];
    
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.centerY.offset(0);
        make.width.mas_lessThanOrEqualTo(200);
    }];
    [tagLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.offset(-15);
        make.centerY.offset(0);
        make.height.offset(fk_adjustW(18));
        make.width.mas_greaterThanOrEqualTo(fk_adjustW(18));
    }];
}

- (void)setData:(id)data
{
    [super setData:data];
    
    if ([data isKindOfClass:[SearchTitleModel class]]) {
        SearchTitleModel *model = data;
        if (model.pid_parent_name.length > 0 && model.pid_name.length > 0 && model.media_class_name.length > 0) {
            self.titleLabel.text = fkFORMAT(@"%@-%@-%@", model.pid_parent_name, model.pid_name, model.media_class_name);
        } else if (model.pid_parent_name.length > 0 && model.pid_name.length > 0) {
            self.titleLabel.text = fkFORMAT(@"%@-%@", model.pid_parent_name, model.pid_name);
        } else if (model.pid_parent_name.length > 0) {
            self.titleLabel.text = model.pid_parent_name;
        }
        
        self.tagLabel.text = model.num;
    }
}

@end
